﻿using System.Collections.Generic;
using YAXLib;

namespace RaytracerLib.Layers
{
    public abstract class BinaryLayer : Layer
    {
        private Layer m_child_layer1;
        private Layer m_child_layer2;

        protected BinaryLayer(Layer a_childLayer1, Layer a_childLayer2)
        {
            ChildLayer1 = a_childLayer1;
            ChildLayer2 = a_childLayer2;
        }

        public override IEnumerable<Layer> Children
        {
            get
            {
                yield return ChildLayer1;
                yield return ChildLayer2;
            }
        }

        [YAXNode("Layer1")]
        public Layer ChildLayer1
        {
            get
            {
                return m_child_layer1;
            }
            set
            {
                if (m_child_layer1 != null)
                    m_child_layer1.Parent = null;
                m_child_layer1 = value;
                if (m_child_layer1 != null)
                    m_child_layer1.Parent = this;
            }
        }

        [YAXNode("Layer2")]
        public Layer ChildLayer2
        {
            get
            {
                return m_child_layer2;
            }
            set
            {
                if (m_child_layer2 != null)
                    m_child_layer2.Parent = null;
                m_child_layer2 = value;
                if (m_child_layer2 != null)
                    m_child_layer2.Parent = this;
            }
        }
    }
}